import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15 as Ctrl2
import QtQuick.Controls 1.4 as Ctrl1
Window {
    id: window
    width: 640
    height: 480
    visible: true

    //时间日期控件
    Ctrl1.Calendar {
        id: calendar
        //第二个参数是月份，0代表一月 11代表12月
        minimumDate: new Date(2017, 0, 1)
        //maximumDate: new Date(2017, 11, 31)
        //无参数是当前时间
        maximumDate: new Date()
        onSelectedDateChanged: {
            console.log(Qt.formatDateTime(selectedDate, "yyyy-MM-dd hh:mm:ss"))
        }
    }

    //下拉框
    Ctrl2.ComboBox {
        anchors.left: calendar.right
        anchors.leftMargin: 20
        editable: true

        //这一行告诉他到底显示listmodel中的哪一个属性(当有多个属性的时候)
        textRole: 'value'
        model: ListModel {
            id: model
            ListElement {
                text: "Banana"
                value: 123
            }
            ListElement {
                text: "Apple"
                value: 456
            }
            ListElement {
                text: "Coconut"
                value: 789
            }
        }
        //选择的时候将内容放到编辑框中
        onAccepted: {
            if (find(editText) === -1)
                model.append({text: editText})
        }
        onActivated: {
            console.log(index)
            let obj = model.get(index)
            console.log(obj.text, obj.value)
        }
    }


    Column {
        //复选框
        anchors.top: calendar.bottom

        Ctrl2.CheckBox {
            checked: true
            text: qsTr("First")
        }
        Ctrl2.CheckBox {
            text: qsTr("Second")
        }
        Ctrl2.CheckBox {
            checked: true
            text: qsTr("Third")

            onCheckedChanged:  {
                if (checked)
                    console.log("checked")
            }
        }
    }
}
